import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/constants/font_family.dart';
import 'package:flutter_eve_plugin/constants/font_weight.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/stageinfo.dart';
import 'package:flutter_eve_plugin/model/ye_xiu/checkpoint/stages.dart';
import 'package:flutter_eve_plugin/store/main.dart';
import 'package:flutter_eve_plugin/store_vm/app_vm.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CheckpointBtnTitleWidget extends StatelessWidget {
  final CheckpointStageInfo info;
  const CheckpointBtnTitleWidget({Key key, this.info}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StoreConnector<AppState, AppStateViewModel>(converter: (store) {
      return AppStateViewModel(state: store.state);
    }, builder: (context, vm) {
      var stages = vm.state.yeXiuState.checkpointState.checkpointStages;
      return Padding(
        padding: EdgeInsets.only(top: setRatio(36)),
        child: Center(
          child: RichText(
            text: TextSpan(
                style: TextStyle(
                    color: Color(0xFFFFFFFF),
                    fontFamily: FontFamily.PINGFANG,
                    fontWeight: FontWeightCustom.PF_Medium,
                    fontSize: setTextSp(12)),
                children: [
                  TextSpan(text: '每日次数：'),
                  TextSpan(
                      text: '${info?.stageBasics?.usrInfo?.leftNum ?? 0}',
                      style: buildTextStyle(stages, info)),
                  TextSpan(
                      text:
                          ' / ${(stages?.isVIP ?? 0) > 0 ? (info?.stageBasics?.configInfo?.vipnum ?? 0) : (info?.stageBasics?.configInfo?.dailynum ?? 0)}'),
                ]),
          ),
        ),
      );
    });
  }

  TextStyle buildTextStyle(CheckpointStages stages, CheckpointStageInfo info) {
    if ((info?.stageBasics?.usrInfo?.leftNum ?? 0) == 0) {
      return TextStyle(color: Color(0xFFFF4C4C));
    } else if ((stages?.isVIP ?? 0) > 0) {
      //会员
      if ((info?.stageBasics?.usrInfo?.leftNum ?? 0) <
          (info?.stageBasics?.configInfo?.vipnum ?? 0)) {
        return TextStyle(color: Color(0xFFFFBF13));
      }
    } else if ((stages?.isVIP ?? 0) <= 0) {
      //非会员
      if ((info?.stageBasics?.usrInfo?.leftNum ?? 0) <
          (info?.stageBasics?.configInfo?.dailynum ?? 0)) {
        return TextStyle(color: Color(0xFFFFBF13));
      }
    }
    return TextStyle(color: Color(0xFFFFFFFF));
  }
}
